﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Text;
using Nissen_Model;

namespace Nissen_Dao
{
	public class WorkerNissenMapLogDao
	{

		public void SaveWorkerNissenMapLog(Worker worker, string loginName)
		{
			string connectionString = ConfigurationManager.AppSettings["DbHelperConnectionStringReport"];
			using (SqlConnection connection = new SqlConnection(connectionString))
			{
				connection.Open();
				SqlTransaction sqlTransaction = connection.BeginTransaction();
				try
				{
					SqlCommand sqlCommand = new SqlCommand();

					sqlCommand.Connection = connection;
					sqlCommand.Transaction = sqlTransaction;
					sqlCommand.CommandText =
						@"INSERT INTO [T_Worker_Nissen_Map]
									   ([WorkerSSO]
										,[WorkerName]
										,[NissenSSO]
										,[CreatDate])
									 VALUES
										   (@WorkerSSO
										   ,@WorkerName
										   ,@NissenSSO
											,GETDATE())";


					;
					sqlCommand.Parameters.Add(new SqlParameter("@WorkerSSO", worker.WorkerSSO));
					sqlCommand.Parameters.Add(new SqlParameter("@WorkerName", loginName));
					sqlCommand.Parameters.Add(new SqlParameter("@NissenSSO", worker.NissenSSO.NissenSSOCode));

					sqlCommand.ExecuteNonQuery();

					sqlTransaction.Commit();
				}
				catch (Exception)
				{

					sqlTransaction.Rollback();
					throw;
				}

			}
		}
	}
}
